$(function () {
    layui.use('form', function () {
        var form = layui.form;
        // layer.msg('玩命卖萌中', function(){
        //   //关闭后的操作
        //   });
        //监听提交
        form.on('submit(login)', function (data) {
            // alert(888)
            // layer.msg(JSON.stringify(data.field), function () {
            //   // location.href = 'index.html'
            // });
            axios.post(`/index/login`, data.field).then(({ data }) => {
                console.log(data);
                if (data.errno != 0) {
                    return layer.msg(`用户名或密码不正确！`)
                }
                localStorage.setItem(`x-token`, data.data.token)
                layer.msg(`登录成功！`, { icon: 1, time: 2000 }, () => {
                    location.href = 'index.html'
                })
            })
            return false;
        });
    });
})